<div class="panel docs-content">
  <!-- 遍历分页后的文章 -->
  {% for post in paginator.posts %} {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %} {% capture this_month
  %}{{ post.date | date: "%B" }}{% endcapture %} {% capture next_year %}{{ post.previous.date | date: "%Y" }}{% endcapture
  %} {% capture next_month %}{{ post.previous.date | date: "%B" }}{% endcapture %} {% if forloop.first %}
  <h2 id="year_{{this_year}}">{{this_year}}</h2>
  <h3 id="month_{{this_year}}_{{this_month}}">{{this_month}}</h3>
  <div>
    {% endif %}

    <!-- 文章列表 -->
    {% include article.html %}

    <hr> {% if forloop.last %}
  </div>
  {% else %} {% if this_year != next_year %}
  </ul>
  <h2 id="year_{{next_year}}">{{next_year}}</h2>
  <h3 id="month_{{next_year}}_{{next_month}}">{{next_month}}</h3>
  <ul>
    {% else %} {% if this_month != next_month %}
  </ul>
  <h3 id="month_{{next_year}}_{{next_month}}">{{next_month}}</h3>
  <ul>
    {% endif %} {% endif %} {% endif %} {% endfor %}
    <!-- 分页链接 -->
    <ul class="pagination">
      <li>
        <a href="/">
          <span>首页</span>
        </a>
      </li>
      <li>
        {% if paginator.page == 1 %}
        <span>&laquo;</span>
        {% else %} {% if paginator.previous_page == 1 %}
        <a href="/">
          {% else %}
          <a href="/page{{ paginator.previous_page }}">
            {% endif %}
            <span>&laquo;</span>
          </a>
          {% endif %}
      </li>
      <li>
        {% assign page_str = '' %} {% assign curr_page_num = paginator.page %} {% assign prev_page_count = 0 %} {% if curr_page_num
        > 1 %} {% assign end = curr_page_num | minus:1 %} {% if curr_page_num
        < 3 or curr_page_num==3 %} {% assign start=1 %} {% else %} {% assign start=c urr_page_num | minus:2 %} {% endif %} {% for
          count in (start..end) %} {% assign page_str=p age_str | append: ',' | append:count %} {% assign prev_page_count=p
          rev_page_count | plus:1 %} {% endfor %} {% endif %} {% assign page_str=p age_str | append: ',' | append:curr_page_num
          %} {% assign last_page_num=p aginator.total_pages %} {% assign next_page_count=0 %} {% if last_page_num> curr_page_num %} {% assign rest_page_count = last_page_num | minus:curr_page_num %} {% assign start = curr_page_num
          | plus:1 %} {% if rest_page_count > 2 %} {% assign end = curr_page_num | plus:2 %} {% if prev_page_count
          < 2 %} {% assign not_enough=2 | minus:prev_page_count %} {% for i in (1..not_enough) %} {% assign try_add_page=e nd | plus:1
            %} {% if try_add_page < last_page_num or try_add_page==l ast_page_num %} {% assign end=t ry_add_page %} {% endif
            %} {% endfor %} {% endif %} {% else %} {% assign end=l ast_page_num %} {% endif %} {% for count in (start..end)
            %} {% assign page_str=p age_str | append: ',' | append:count %} {% assign next_page_count=n ext_page_count | plus:1
            %} {% endfor %} {% endif %} {% if next_page_count < 2 and curr_page_num> 2 %} {% assign not_enough = 2 | minus:next_page_count %} {% for i in (1..not_enough) %} {% assign try_add_page
            = curr_page_num | minus:3 %} {% if try_add_page > 1 or try_add_page == 1 %} {% assign page_str = page_str | prepend:try_add_page
            | prepend:',' %} {% assign curr_page_num = curr_page_num | minus:1 %} {% endif %} {% endfor %} {% endif %} {%
            assign page_str = page_str | replace_first:',','' %} {% assign page_arr = page_str | split:',' %} {% assign curr_page_num
            = paginator.page | append:'' %} {% for count in page_arr %} {% if count == curr_page_num %}
            <span class="active">{{ count }}</span>
            {% elsif count == '1' %}
            <a href="/">{{ count }}</a>
            {% else %}
            <a href="/page{{ count }}/">{{ count }}</a>
            {% endif %} {% endfor %}
      </li>
      <li>
        {% if paginator.page == paginator.total_pages %}
        <span>&raquo;</span>
        {% else %}
        <a href="/page{{ paginator.next_page }}">
          <span>&raquo;</span>
        </a>
        {% endif %}
      </li>
      <li>
        <a href="/page{{paginator.total_pages}}">
          <span>末页</span>
        </a>
      </li>
    </ul>
</div>